const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();

// 聚合记录云函数入口函数
exports.main = async (event, context) => {
  const user = event.user
  if (user.nick_name == '江多') {
    user.type = '超级管理员'
  }
  user.create_time = new Date()
  try {
    db.collection('sys_user').add({
      data: {
        user
      }
    }).then(res => {
      console.log(res, ' add done ...')
    })
  } catch (e) {
    console.log(e,' user add err ...')
  }
  return true;
};